package com.shxc.smarttrade.old.foreignfragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.shxc.smarttrade.R;
import com.shxc.smarttrade.old.adapternew.QuotationAdapter;
import com.shxc.smarttrade.old.myview.RecycleViewTwoDivider;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by jcdev1 on 2017/10/25.
 */

public class OptionalFragment extends Fragment {

    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    private View rootView;
    private QuotationAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.optional_fragment, null);
        }
        //缓存的rootView需要判断是否已经被加过parent， 如果有parent需要从parent删除，要不然会发生这个rootview已经有parent的错误。
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null) {
            parent.removeView(rootView);
        }
        ButterKnife.bind(this, rootView);
        initView();
        return rootView;
    }

    private void initView() {
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(manager);
        recyclerView.addItemDecoration(new RecycleViewTwoDivider(getContext(), LinearLayout.VERTICAL, 1, getResources().getColor(R.color.dividing_line_color)));
        recyclerView.setAdapter(adapter = new QuotationAdapter(getContext()));
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}
